<template>
	<view class="user-container" @touchmove.prevent @touchstart="handleTouchStart" @touchend="handleTouchEnd">
		<!-- 用户信息卡片 -->
		<view class="user-card">
			<view class="avatar-container">
				<view class="avatar">
					<image src="https://via.placeholder.com/80" alt="头像" />
				</view>
			</view>
			<view class="user-info">
				<view class="username-container">
					<text class="username">用户名</text>
					<text class="verified-badge">已认证</text>
				</view>
				<text class="user-id">ID: 000000</text>
			</view>
			<!-- 设置按钮 -->
			<view class="edit-profile" @click="goToSettings">
				<text class="icon-text">⚙️</text>
			</view>
		</view>

		<!-- 钱包卡片 -->
		<view class="wallet-card" @click="goToWallet">
			<text class="wallet-title">我的钱包</text>
			<text class="wallet-amount">¥0.00</text>
			<view class="wallet-arrow">
				<text class="icon-text">❯</text>
			</view>
		</view>

		<!-- 功能菜单列表 -->
		<view class="menu-list">
			<view class="menu-item" v-for="(item, index) in menuItems" :key="index">
				<view class="menu-icon">
					<text class="icon-text">{{ item.icon }}</text>
				</view>
				<text class="menu-text">{{ item.text }}</text>
				<view class="menu-arrow">
					<text class="icon-text">❯</text>
				</view>
			</view>
		</view>

		<!-- 内容区域 -->
		<view class="content-container">
			<!-- 导航栏 -->
			<view class="tab-navigation">
				<view class="tabs-wrapper">
					<view 
						v-for="(tab, index) in tabs" 
						:key="index" 
						class="tab" 
						:class="{ 'active': activeTab === index }"
						@click="setActiveTab(index)"
					>
						{{ tab.name }} <text class="tab-count">{{ tab.count }}</text>
					</view>
				</view>
			</view>
			
			<!-- 标签内容 -->
			<view class="tab-content">
				<transition :name="slideDirection">
					<view v-if="activeTab === 0" class="tab-panel" key="collections">
						<!-- 空状态展示 -->
						<view class="empty-state">
							<view class="search-bar">
								<text class="icon-text">🔍</text>
								<input type="text" placeholder="搜索我的藏品" />
							</view>
							<view class="empty-content">
								<image src="https://via.placeholder.com/150" alt="空盒子" class="empty-box-image" />
								<text class="empty-text">暂无收藏记录</text>
							</view>
						</view>
					</view>
				</transition>

				<transition :name="slideDirection">
					<view v-if="activeTab === 1" class="tab-panel" key="blindboxes">
						<view class="empty-state">
							<view class="empty-content">
								<image src="https://via.placeholder.com/150" alt="空盒子" class="empty-box-image" />
								<text class="empty-text">暂无盲盒</text>
							</view>
						</view>
					</view>
				</transition>

				<transition :name="slideDirection">
					<view v-if="activeTab === 2" class="tab-panel" key="props">
						<view class="empty-state">
							<view class="empty-content">
								<image src="https://via.placeholder.com/150" alt="空盒子" class="empty-box-image" />
								<text class="empty-text">暂无道具</text>
							</view>
						</view>
					</view>
				</transition>
			</view>
		</view>

		<!-- 底部 LOGO -->
		<view class="footer">
			<view class="logo">LianArt</view>
			<view class="platform-name">数字藏品平台</view>
		</view>
	</view>
</template>



<script>
	import { mapState } from 'vuex'

	export default {
		data() {
			return {
				menuItems: [
					{ text: "订单记录", icon: "🛒" },
					{ text: "认证中心", icon: "✅" },
					{ text: "邀请好友", icon: "👥" },
					{ text: "关于我们", icon: "ℹ️" }
				],
				tabs: [
					{ name: "藏品", count: 0 },
					{ name: "盲盒", count: 0 },
					{ name: "道具", count: 0 }
				],
				activeTab: 0,
				slideDirection: 'slide-right',
				lastActiveTab: 0,
				startX: 0,
				endX: 0
			};
		},
		computed: {
			...mapState('user', ['isLogin', 'userInfo'])
		},
		onShow() {
			// 每次页面显示时检查登录状态
			if (!this.isLogin) {
				uni.redirectTo({
					url: '/pages/auth/login'
				})
			}
		},
		methods: {
				setActiveTab(index) {
					this.slideDirection = index > this.lastActiveTab ? 'slide-left' : 'slide-right';
					this.lastActiveTab = this.activeTab;
					this.activeTab = index;
				},
				//前往钱包
				goToWallet() {
					uni.navigateTo({
						url: '/pages/main/user/userwallet',
						animationType: 'pop-in',
						animationDuration: 300
					});
				},
				//前往设置
				goToSettings() {
					uni.navigateTo({
						url: '/pages/user-setting/setting-index'
					});
				},
				applyStatusBarHeight(height) {
					const container = document.querySelector('.user-container');
					if (container) {
						container.style.paddingTop = (height + 10) + 'px'; // 状态栏高度 + 额外间距
					}
				},
				handleTouchStart(e) {
					this.startX = e.touches[0].clientX;
				},
				handleTouchEnd(e) {
					this.endX = e.changedTouches[0].clientX;
					const diffX = this.startX - this.endX;
					
					// 判断是否为水平滑动
					if (Math.abs(diffX) > 50) {
						// 发送滑动方向
						this.$emit('swipe', diffX > 0 ? 'left' : 'right');
					}
				}
			},
			head() {
				return {
					link: [
						{ rel: 'stylesheet', href: 'https://fonts.googleapis.com/icon?family=Material+Icons' }
					]
				}
			},
			onLoad() {
				// 获取状态栏高度并应用
				const app = getApp();
				if (app.globalData.statusBarHeight) {
					this.applyStatusBarHeight(app.globalData.statusBarHeight);
				} else {
					uni.getSystemInfo({
						success: (res) => {
							this.applyStatusBarHeight(res.statusBarHeight);
						}
					});
				}
		}

	}
</script>

<style scoped>
/* 基础样式 */
.user-container {
	background-color: #9BBFE0;
	min-height: 100vh;
	width: 100%;
	max-width: 100%;
	padding: 16px;
	padding-top: 40px !important;
	font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
	color: #333;
	box-sizing: border-box;
	overflow-x: hidden !important;
	overflow-y: auto !important;
	margin: 0;
	padding-bottom: 56px; /* 为底部导航栏留出空间 */
	-webkit-overflow-scrolling: touch; /* 提升iOS滚动体验 */
}

.user-container::-webkit-scrollbar {
	display: none !important;
	width: 0 !important;
	height: 0 !important;
}

/* 确保所有元素都使用border-box盒模型 */
* {
	box-sizing: border-box;
}

/* 用户信息卡片 */
.user-card {
	background: rgba(255, 255, 255, 0.9);
	border-radius: 16px;
	padding: 16px;
	display: flex;
	align-items: center;
	margin-bottom: 16px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	position: relative;
	width: 100%;
}

.avatar-container {
	margin-right: 12px;
	flex-shrink: 0;
}

.avatar {
	width: 60px;
	height: 60px;
	border-radius: 50%;
	overflow: hidden;
	border: 3px solid #fff;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.avatar image {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.user-info {
	flex: 1;
	min-width: 0; /* 防止flex子项溢出 */
}

.username-container {
	display: flex;
	align-items: center;
	margin-bottom: 5px;
	flex-wrap: wrap;
}

.username {
	font-size: 18px;
	font-weight: 600;
	margin: 0;
	margin-right: 8px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.verified-badge {
	background-color: #ff6b6b;
	color: white;
	padding: 2px 6px;
	border-radius: 10px;
	font-size: 11px;
	white-space: nowrap;
}

.user-id {
	color: #888;
	margin: 0;
	font-size: 13px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* 用户操作区域 */
.edit-profile {
	position: absolute;
	top: 50%;
	right: 16px;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.05);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transform: translateY(-50%);
}

/* 钱包卡片 */
.wallet-card {
	background: linear-gradient(135deg, #ffafbd, #ffc3a0);
	border-radius: 16px;
	padding: 16px;
	margin-bottom: 16px;
	display: flex;
	align-items: center;
	position: relative;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	color: #fff;
	width: 100%;
}

.wallet-title {
	font-size: 16px;
	font-weight: 500;
	flex: 1;
}

.wallet-amount {
	font-size: 20px;
	font-weight: 600;
	margin-right: 12px;
}

.wallet-arrow {
	width: 24px;
	height: 24px;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* 功能菜单列表 */
.menu-list {
	background: rgba(255, 255, 255, 0.9);
	border-radius: 16px;
	overflow: hidden;
	margin-bottom: 16px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	width: 100%;
}

.menu-item {
	padding: 14px 16px;
	display: flex;
	align-items: center;
	border-bottom: 1px solid rgba(0, 0, 0, 0.05);
	cursor: pointer;
	transition: background-color 0.2s ease;
}

.menu-item:last-child {
	border-bottom: none;
}

.menu-item:hover {
	background-color: rgba(0, 0, 0, 0.02);
}

.menu-icon {
	width: 22px;
	height: 22px;
	margin-right: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #4299e1;
	flex-shrink: 0;
}

.menu-text {
	flex: 1;
	font-size: 15px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.menu-arrow {
	color: #ccc;
	flex-shrink: 0;
}

/* 内容容器 */
.content-container {
	background: rgba(255, 255, 255, 0.9);
	border-radius: 16px;
	overflow: hidden;
	margin-bottom: 16px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
	width: 100%;
}

/* 导航栏 */
.tab-navigation {
	width: 100%;
	overflow-x: auto;
	padding: 0 16px;
	border-bottom: 1px solid rgba(0, 0, 0, 0.05);
	-webkit-overflow-scrolling: touch; /* 提升iOS滚动体验 */
	scrollbar-width: none; /* Firefox */
}

.tab-navigation::-webkit-scrollbar {
	display: none; /* Chrome, Safari, Edge */
}

.tabs-wrapper {
	display: flex;
	justify-content: center; /* 居中显示标签 */
	min-width: 100%; /* 确保占满容器宽度 */
	padding: 12px 0;
}

.tab {
	padding: 4px 12px;
	margin: 0 16px; /* 修改为左右边距相等 */
	white-space: nowrap;
	font-size: 15px;
	font-weight: 500;
	color: rgba(0, 0, 0, 0.6);
	position: relative;
	cursor: pointer;
	transition: all 0.2s ease;
}

.tab:last-child {
	margin-right: 0;
}

.tab.active {
	color: #000;
	font-weight: 600;
}

.tab-count {
	margin-left: 4px;
	opacity: 0.8;
}

/* 标签内容 */
.tab-content {
	position: relative;
	overflow: hidden;
	min-height: 300px;
}

/* 搜索栏 */
.search-bar {
	background: rgba(0, 0, 0, 0.05);
	border-radius: 8px;
	padding: 8px 12px;
	display: flex;
	align-items: center;
	margin: 16px;
}

.search-bar text {
	color: #888;
	margin-right: 8px;
}

.search-bar input {
	flex: 1;
	border: none;
	background: none;
	font-size: 14px;
	color: #333;
	outline: none;
	height: 24px;
}

/* 空状态 */
.empty-state {
	display: flex;
	flex-direction: column;
	height: 100%;
	min-height: 300px;
}

.empty-content {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	padding: 32px 16px;
}

.empty-box-image {
	width: 120px;
	height: 120px;
	margin-bottom: 16px;
	opacity: 0.7;
}

.empty-text {
	font-size: 16px;
	color: #888;
	text-align: center;
}

/* 底部 LOGO */
.footer {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 16px 0;
	opacity: 0.7;
	width: 100%;
}

.logo {
	font-size: 16px;
	font-weight: 600;
	margin-bottom: 4px;
}

.platform-name {
	font-size: 13px;
}

/* 响应式设计 - 针对不同手机尺寸优化 */
@media (max-width: 375px) {
	.user-container {
		padding: 12px;
	}
	
	.avatar {
		width: 50px;
		height: 50px;
	}
	
	.username {
		font-size: 16px;
	}
	
	.verified-badge {
		font-size: 10px;
		padding: 1px 5px;
	}
	
	.wallet-amount {
		font-size: 18px;
	}
	
	.menu-item {
		padding: 12px 14px;
	}
	
	.menu-text {
		font-size: 14px;
	}
	
	.tab {
		padding: 4px 10px;
		font-size: 14px;
		margin: 0 12px;
	}
	
	.empty-box-image {
		width: 100px;
		height: 100px;
	}
	
	.empty-text {
		font-size: 14px;
	}
}

/* 动画效果 */
@keyframes fadeIn {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: translateY(0); }
}

.user-card, .wallet-card, .menu-list, .content-container {
	animation: fadeIn 0.5s ease forwards;
}

.menu-item:nth-child(1) { animation-delay: 0.1s; }
.menu-item:nth-child(2) { animation-delay: 0.2s; }
.menu-item:nth-child(3) { animation-delay: 0.3s; }
.menu-item:nth-child(4) { animation-delay: 0.4s; }

.tab:nth-child(1) { animation: fadeIn 0.3s ease forwards; }
.tab:nth-child(2) { animation: fadeIn 0.3s ease forwards; animation-delay: 0.05s; }
.tab:nth-child(3) { animation: fadeIn 0.3s ease forwards; animation-delay: 0.1s; }

.icon-text {
	font-size: 18px;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* 标签内容面板 */
.tab-panel {
	position: absolute;
	width: 100%;
	transition: all 0.3s;
}

/* 向左滑动动画 */
.slide-left-enter-active,
.slide-left-leave-active,
.slide-right-enter-active,
.slide-right-leave-active {
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	position: absolute;
	width: 100%;
}

.slide-left-enter-from {
	transform: translateX(100%);
	opacity: 0;
}

.slide-left-leave-to {
	transform: translateX(-100%);
	opacity: 0;
}

.slide-right-enter-from {
	transform: translateX(-100%);
	opacity: 0;
}

.slide-right-leave-to {
	transform: translateX(100%);
	opacity: 0;
}
</style>